/**
 * 智慧小区管理系统 - 小区管理API接口
 * @author Wu.Liang
 * @date 2024-12-21
 * @updated 2024-12-21 - 完善小区管理API接口，遵循Controller命名规范
 */
import api from './request'
import type { ApiResponse } from './request'

// 小区相关类型定义
export interface CommunityData {
  id: number
  communityName: string
  communityCode: string
  regionId: number
  regionName: string
  address: string
  latitude: number
  longitude: number
  totalBuildings: number
  totalHouseholds: number
  occupancyRate: number
  buildingTypes?: string[]
  contactPhone: string
  managerName: string
  remark: string
  status: number
  createTime: string
  updateTime: string
}

export interface CreateCommunityDTO {
  communityName: string
  communityCode: string
  regionId: number
  propertyCompanyId?: number
  address: string
  latitude: number
  longitude: number
  contactPhone?: string
  managerName?: string
  remark?: string
  status: number
}

export interface UpdateCommunityDTO {
  communityName?: string
  communityCode?: string
  regionId?: number
  propertyCompanyId?: number
  address?: string
  latitude?: number
  longitude?: number
  contactPhone?: string
  managerName?: string
  remark?: string
  status?: number
}

export interface CommunityQueryDTO {
  communityName?: string
  communityCode?: string
  regionId?: number
  status?: number
  ids?: string // 小区ID列表，逗号分隔
  pageNum?: number
  pageSize?: number
}

// 小区API接口
export const communityApi = {
  /**
   * 获取小区列表（全部，不分页）
   * @author Wu.Liang
   */
  getCommunityList: (params: CommunityQueryDTO) => 
    api.get<ApiResponse<CommunityData[]>>('/api/region/communities/list', { params }),

  /**
   * 获取小区分页列表
   * @author Wu.Liang
   */
  getCommunityPage: (params: CommunityQueryDTO) => 
    api.get<ApiResponse<any>>('/api/region/communities', { params }),

  /**
   * 获取小区详情
   * @author Wu.Liang
   */
  getCommunityDetail: (id: number) => 
    api.get<ApiResponse<CommunityData>>(`/api/region/communities/${id}`),

  /**
   * 创建小区
   * @author Wu.Liang
   */
  createCommunity: (data: CreateCommunityDTO) => 
    api.post<ApiResponse<void>>('/api/region/communities', data),

  /**
   * 更新小区
   * @author Wu.Liang
   */
  updateCommunity: (id: number, data: UpdateCommunityDTO) => 
    api.put<ApiResponse<void>>(`/api/region/communities/${id}`, data),

  /**
   * 删除小区
   * @author Wu.Liang
   */
  deleteCommunity: (id: number) => 
    api.delete<ApiResponse<void>>(`/api/region/communities/${id}`),

  /**
   * 获取小区统计信息
   * @author Wu.Liang
   */
  getCommunityStatistics: (id?: number) => 
    api.get<ApiResponse<any>>('/api/region/communities/statistics', { params: { id } })
} 